using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommerceOne.Domains.IRepositories;
using CommerceOne.Models.Entities;
namespace CommerceOne.Domains.SqlRepositories
{
    public class SqlAddressRepository : SqlRepositoryBase, IAddressRepository
    {
        public void Add(Address address)
        {
            address.ModifiedDate = DateTime.Now;
            this.SqlContext.Addresses.Add(address);
            int resut = this.SqlContext.SaveChanges();
            if (resut == 0) throw new Exception("None row is inserted.");
        }

        public List<Address> GetByUser(int userId)
        {
            return this.SqlContext.Addresses.Where(x => x.ContactID == userId).ToList();
        }

        #region Singleton Instance
        private static SqlAddressRepository _instance;
        public static SqlAddressRepository Instance
        {
            get
            {
                if (_instance == null) _instance = new SqlAddressRepository();
                return _instance;
            }
        }
        #endregion
    }
} 
